using UnityEngine;
using System.Collections;

namespace RichLabelSpace
{
	public class RichTexture : RichLabelComponent
	{
        UITexture m_texture = null;
        string m_tex_name = null;
        int m_width = 0;
        int m_height = 0;

        protected override void SetProperty(string[] property)
        {
            if (property[0].Equals("texture_name"))
            {
                this.m_tex_name = property[1];
            }
            else if (property[0].Equals("width"))
            {
                this.m_width = int.Parse(property[1]);
            }
            else if (property[0].Equals("height"))
            {
                this.m_height = int.Parse(property[1]);
            }
        }
        public override void Excute()
        {
            this.m_texture.mainTexture = Resources.Load<Texture>(this.m_tex_name);
            this.m_texture.pivot = UIWidget.Pivot.Left;
            this.m_texture.MakePixelPerfect();
            if (m_width > 0) m_texture.width = m_width;
            if (m_height > 0) m_texture.height = m_height;
            RichLabelCtrl.ResetGameObj(this.m_ui_widget.gameObject, this.m_parent);
        }
        public RichTexture(Transform parent, RichLabelCtrl ctrl)
            : base(parent, ctrl)
        {
            var go = new GameObject();
            go.name = "RichTexture";
            go.transform.SetParent(parent);
            this.m_texture = go.AddComponent<UITexture>();
            this.m_ui_widget = this.m_texture;
        }

    }
}
